package myJs.user.mission.plot

import io.scalaland.chimney.dsl._
import myJs.Implicits.JDJAn
import shared.Pojo._

import scala.scalajs.js.JSON
import myJs.components.{FontArgComponent, PlotLayoutComponent}
import myJs.components.lefse._
import monocle.macros.Lenses
import myJs.Implicits._
import myJs.components.FontArgComponent._
import upickle.default._

/**
 * Created by yz on 20/1/2021
 */
object AllPlotDataTool {

  def getData(rs: JDJAn) = {
    read[AllPlotData](JSON.stringify(rs))
  }

  def getState(data: AllPlotData) = {
    FontArgComponent.State.init.copy(
      sampleFontShow = data.showSample == "T",
      envFontShow = data.layout.showEnv == "T", speciesFontShow = data.layout.showSpecies == "T",
    ).using(data).ignoreRedundantPatcherFields.patch
  }

  def getLdaLayoutState(data: AllPlotData) = {
    LdaLayoutComponent.State.init.using(data).ignoreRedundantPatcherFields.patch
  }

  def getCladogramLayoutState(data: AllPlotData) = {
    CladogramLayoutComponent.State.init.using(data).ignoreRedundantPatcherFields.patch
  }

  def getPlotLayoutState(data: AllPlotData) = {
    PlotLayoutComponent.State.init.using(data).ignoreRedundantPatcherFields.patch
  }

}
